package cloud.xlh.my_system.controller;

import cloud.xlh.my_system.common.response.Response;
import cloud.xlh.my_system.pojo.Database;
import cloud.xlh.my_system.service.DatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : code-generator
 * @ Author: XuLeHuang
 * @ Date: 2022/5/31 10:47
 * @ Description:
 */
@Controller
@RequestMapping("/database")
public class DatabaseController {

    @Autowired
    private DatabaseService dataBaseService;

    @RequestMapping("/toListPage")
    public String toListPage() {
        return "/database-manage/list";
    }

    @RequestMapping("/getListData")
    @ResponseBody
    public Response<HashMap> getListData(Integer limit , Integer page) {
        return dataBaseService.getListData(limit , page);
    }

    @RequestMapping("/toAddPage")
    public String toAddPage() {
        return "/database-manage/add";
    }

    @RequestMapping("/add")
    @ResponseBody
    public Response<String> add(@RequestBody Database database) {
        return dataBaseService.add(database);
    }

    @RequestMapping("/connectTest")
    @ResponseBody
    public Response<Boolean> connectTest(@RequestBody Database database) {
        return dataBaseService.connectTest(database);
    }

    @GetMapping("/option")
    @ResponseBody
    public Response<List<Database>> option(Database database) {
        return dataBaseService.option(database);
    }

    @PostMapping("/newTableLoading")
    @ResponseBody
    public Response<String> newTableLoading(@RequestBody Database database) {
        return dataBaseService.newTableLoading(database);
    }
}
